home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / viewwrld / viewwrld.lha / viewworld / gr / window2.c < prev   
Encoding:
C/C++ Source or Header  |  1989-09-21  |  29.1 KB  |  1,005 lines

  1. /* $Id: window2.c,v 2.3 89/09/20 17:01:51 mbp Exp $
  2.  *
  3.  * window2.c:
  4.  *   This is the 2nd half of window.c; it is #included by window.c.
  5.  *   Do not try to compile this separately!
  6.  */
  7.  
  8. /************************************************************************
  9.  *                                    *
  10.  *         P R I V A T E    P R O C E D U R E S            *
  11.  *                                                                      *
  12.  *     Anything below here is for use only within this file           *
  13.  ************************************************************************/
  14.  
  15. /************************************************************************
  16.  *       PRIVATE PROCEDURES COMMON TO 2D VERSION AND 3D VERSION:        *
  17.  ************************************************************************/
  18.  
  19. /*-----------------------------------------------------------------------
  20.  * Function:    quit_button_proc
  21.  * Description:    respond to quit button
  22.  * Args:    (none)
  23.  * Notes:    Causes gr_main_loop to return (after user confirmation).
  24.  *        Normally this is the end of the program.
  25.  */
  26. static int
  27. quit_button_proc()
  28. {
  29.   window_done(GR_base_frame);
  30. }
  31.  
  32. /*-----------------------------------------------------------------------
  33.  * Function:    button_event_proc
  34.  * Description:    respond to a button in the control panel
  35.  * Args  IN:    item: handle of button which received event
  36.  *        event: the event
  37.  * Notes:    Display's button's menu if appropriate
  38.  */
  39. static int
  40. button_event_proc(item, event)
  41.      Panel_item item;
  42.      Event *event;
  43. {
  44.   /* If event is right mouse button going down, display button's menu */
  45.   if ( (event_id(event)==MS_RIGHT) && (event_is_down(event)) ) {
  46.  
  47.     /* Buttons present in both 2D and 3D versions: */
  48.  
  49.     /* control panel buttons */
  50.     if (item==help_button)
  51.       menu_show(help_button_menu, GR_control_panel, event, 0);
  52.     else if (item==print_button)
  53.       menu_show(print_button_menu, GR_control_panel, event, 0);
  54.     else if (item==quit_button)
  55.       menu_show(quit_button_menu, GR_control_panel, event, 0);
  56.  
  57.     /* Buttons present in 3D version only: */
  58. #ifdef THREE_D
  59.  
  60.     /* view control panel buttons: */
  61.     else if (item==horizontal_pan_button)
  62.       menu_show(horizontal_pan_button_menu, GR_view_control_panel, event, 0);
  63.     else if (item==horizontal_sweep_button)
  64.       menu_show(horizontal_sweep_button_menu, GR_view_control_panel, event, 0);
  65.     else if (item==perspective_button)
  66.       menu_show(perspective_button_menu, GR_view_control_panel, event, 0);
  67.     else if (item==anim_button)
  68.       menu_show(anim_button_menu, GR_view_control_panel, event, 0);
  69.     else if (item==reset_button)
  70.       menu_show(reset_button_menu, GR_view_control_panel, event, 0);
  71.     else if (item==tilt_button)
  72.       menu_show(tilt_button_menu, GR_view_control_panel, event, 0);
  73.     else if (item==vertical_pan_button)
  74.       menu_show(vertical_pan_button_menu, GR_view_control_panel, event, 0);
  75.     else if (item==vertical_sweep_button)
  76.       menu_show(vertical_sweep_button_menu, GR_view_control_panel, event, 0);
  77.     else if (item==view_data_button)
  78.       menu_show(view_data_button_menu, GR_view_control_panel, event, 0);
  79.     else if (item==zoom_button)
  80.       menu_show(zoom_button_menu, GR_view_control_panel, event, 0);
  81.     else if (item==redraw_button)
  82.       menu_show(redraw_button_menu, GR_view_control_panel, event, 0);
  83.  
  84.     /* view_data_panel buttons: */
  85.     else if (item==view_data_redraw_button)
  86.       menu_show(redraw_button_menu, view_data_panel, event, 0);
  87.  
  88. #endif /* End of 3D version buttons */
  89.  
  90.     /* Then move mouse cursor back to where it was before menu display */
  91.     window_set((Panel)panel_get(item, PANEL_PARENT_PANEL),
  92.            WIN_MOUSE_XY, event_x(event), event_y(event),
  93.            0);
  94.   }
  95.  
  96.   /* Otherwise, do the normal thing for this button */
  97.   else
  98.     panel_default_handle_event(item, event);
  99. }
  100.  
  101. /*-----------------------------------------------------------------------
  102.  * Function:    help_button_proc
  103.  * Description:    respond to help button
  104.  * Args:    (none)
  105.  * Notes:    displays the help window
  106.  */
  107. static int
  108. help_button_proc()
  109. {
  110.   GR_display_help_window();
  111. }
  112.  
  113. /*-----------------------------------------------------------------------
  114.  * Function:    canvas_event_proc
  115.  * Description:    Handle an event which has occurred in the canvas
  116.  * Args  IN:    window: canvas's handle
  117.  *        *event: the event
  118.  *        arg: ?????? (unused)
  119.  * Returns:    success status
  120.  */
  121. static int
  122. canvas_event_proc(window, event, arg)
  123.      Window window;
  124.      Event *event;
  125.      caddr_t arg;
  126. {
  127.   int menu_opt;
  128.   
  129.   /* Make sure that an application menu is defined; (if none is, just
  130.    * ignore all events) */
  131.   if (GR_current_menu.title != NULL) {
  132.     
  133.     /* If the event was the right mouse button going down, */
  134.     if ( (event_id(event) == MS_RIGHT) && (event_is_down(event)) ) {
  135.       
  136.       /* display the application menu and get option from user. */
  137.       menu_opt = (int)menu_show(app_menu, window, event, 0);
  138.       
  139.       /* If number returned is >0, execute corresponding menu proc. */
  140.       if (menu_opt>0) (*(GR_current_menu.list[menu_opt-1].proc))();
  141.       
  142.       /* (0 means user didn't pick an option, so don't do anything.) */
  143.     }
  144.   }
  145.   
  146. }
  147.  
  148. /*-----------------------------------------------------------------------
  149.  * Function:    app_menu_operation
  150.  * Description:    do an operation with the application menu
  151.  * Args  IN:    m: the menu's handle
  152.  *        operation: the operation to perform
  153.  * Returns:    m
  154.  */
  155. static Menu
  156. app_menu_operation(m, operation)
  157.      Menu        m;
  158.      Menu_generate    operation;
  159. {
  160.   int i;
  161.   static int display_is_current_menu=0;
  162.   
  163.   switch (operation) {
  164.   case MENU_DISPLAY:
  165.     /* The menu is about to be displayed; set the entries to those of
  166.      * the current menu, unless this has already been done for this
  167.      * menu. */
  168.     if (!display_is_current_menu) {
  169.       menu_set(m, MENU_TITLE_ITEM, GR_current_menu.title, 0);
  170.       for (i=0; i<GR_current_menu.nopts; ++i)
  171.     menu_set(m, MENU_STRING_ITEM, GR_current_menu.list[i].string, i+1, 0);
  172.       display_is_current_menu=1;
  173.     }
  174.     break;
  175.   
  176.   case MENU_DISPLAY_DONE:
  177.   case MENU_NOTIFY:
  178.     /* Don't do anything for these cases */
  179.     break;
  180.   
  181.   case MENU_NOTIFY_DONE:
  182.     /* We are finished with the menu for this round.
  183.      * Destroy it and make a new one to be used next
  184.      * time. */
  185.     menu_destroy(m);
  186.     m = menu_create(MENU_GEN_PROC, app_menu_operation, 0);
  187.     display_is_current_menu=0;
  188.     app_menu = m;
  189.     break;
  190.   }
  191.  
  192.   return(m);
  193. }
  194.  
  195. /*-----------------------------------------------------------------------
  196.  * Function:    process_ascii_event
  197.  * Description:    Process an ascii event which occured while waiting for
  198.  *        the user to type in a string.
  199.  * Args  IN:    *event: the event to process
  200.  * Returns:    1 if we're done (i.e. the event was a carriage return),
  201.  *        0 otherwise
  202.  */
  203. static
  204. process_ascii_event(event)
  205.      Event *event;
  206. {
  207. #define CR        0x0d    /* <carriage return>    */
  208. #define DEL        0x7f    /* <del>        */
  209. #define BS        0x08    /* <ctrl>-h        */
  210. #define LINEKILL    0x15    /* <ctrl>-u        */
  211. #define DONE        1
  212. #define NOT_DONE    0
  213.  
  214.    char *str, text_string[GR_INPUT_TEXT_LENGTH+1];
  215.    int len;
  216.  
  217.    /* If this is not the event going down, do nothing */
  218.    if (!event_is_down(event)) return(NOT_DONE);
  219.  
  220.    /* Get the current string from the application text item */
  221.    str = (char *)panel_get (app_text, PANEL_VALUE);
  222.    len = strlen (str);
  223.  
  224.    /* Copy it to our buffer */
  225.    strcpy (text_string, str);
  226.  
  227.    /* Now act on the buffer according to what the event was */
  228.    switch (event_id(event)) {
  229.  
  230.    case CR:            /* We are done reading */
  231.      return(DONE);
  232.      break;
  233.  
  234.    case BS:            /* backspace or delete */
  235.    case DEL:
  236.      if (len > 0) {
  237.        text_string[len-1] = '\0';
  238.      }
  239.      break;
  240.  
  241.    case LINEKILL:        /* kill entire line */
  242.      text_string[0]='\0';
  243.      break;
  244.  
  245.    default:            /* just append the char */
  246.      /* ... but first make sure there's room! */
  247.      if (len < GR_INPUT_TEXT_LENGTH) {
  248.        text_string[len] = (char)event_id(event);
  249.        text_string[len+1] = '\0';
  250.      }
  251.      break;
  252.  
  253.    }
  254.  
  255.    /* Now redisplay the string, since it might have been modified */
  256.    panel_set(app_text, PANEL_VALUE, text_string, 0 );
  257.  
  258.    return(NOT_DONE);
  259.  
  260. #undef CR
  261. #undef DEL
  262. #undef BS
  263. #undef LINEKILL
  264. #undef DONE
  265. #undef NOT_DONE
  266. }
  267.  
  268. /* -----------------------------------------------------------------------
  269.  * Function:    interposer
  270.  * Description:    interposition proc to clear error messages
  271.  * Args:    (see SunView Programmer's Guide)
  272.  * Notes:    This procedure is placed just ahead of (in the notification
  273.  *         sequence) the event procedure for every window in the
  274.  *         program (except the confirmer window) to do any
  275.  *         necessary preprocessing of events.  At present, it is
  276.  *         used just to clear any error messages which need to be
  277.  *         cleared from the error panel.
  278.  */
  279. static Notify_value
  280. interposer(client, event, arg, type)
  281.      Notify_client;
  282.      Event *event;
  283.      Notify_arg arg;
  284.      Notify_event_type type;
  285. {
  286.   Notify_value value;
  287.  
  288.   /* If this is a mouse event, clear any error messages */
  289.   switch (event_id(event)) {
  290.   case MS_LEFT:
  291.   case MS_MIDDLE:
  292.   case MS_RIGHT:
  293.     if (error_message_present) {
  294.       if (!hold_error_message) {
  295.     GR_message("");
  296.     error_message_present = 0;
  297.       }
  298.       else
  299.     --hold_error_message;
  300.     }
  301.     break;
  302.   default:
  303.     break;
  304.   }
  305.  
  306.   /* proceed with normal notification */
  307.   return( notify_next_event_func(client, event, arg, type) );
  308. }
  309.  
  310. /*-----------------------------------------------------------------------
  311.  * Function:    register_interposer_window
  312.  * Description:    register our interposer (procedure "interposer" above)
  313.  *          for a window
  314.  * Args  IN:    window: the window's handle
  315.  * Notes:    This procedure does it for a single window.
  316.  *        GR_register_interposer does it for a whole window tree.
  317.  */
  318. static int
  319. register_interposer_window(window)
  320.      Window window;
  321. {
  322.   notify_interpose_event_func(window, interposer, NOTIFY_SAFE);
  323. }
  324.  
  325. /************************************************************************
  326.  *          PRIVATE PROCEDURES SPECIFIC TO 3D VERSION:                *
  327.  ************************************************************************/
  328.  
  329. #ifdef THREE_D
  330.  
  331. static int
  332. initialize_view_control_panel()
  333. {
  334.   int i;
  335.  
  336.   read_defaults();
  337.  
  338.   GR_view_control_panel =
  339.      window_create(GR_base_frame, PANEL,
  340.     WIN_X, 840,
  341.     WIN_Y, 85,
  342.     WIN_WIDTH, 150,
  343.     WIN_HEIGHT, 692,
  344.     WIN_FONT, GR_regular_font,
  345.     0);
  346.   if (GR_view_control_panel == NULL) goto BAD_WINDOW_ERROR;
  347.  
  348.   horizontal_sweep_button =
  349.      panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  350.                PANEL_ITEM_X, 1,
  351.                PANEL_ITEM_Y, 1,
  352.                PANEL_LABEL_IMAGE, &horizontal_sweep_pr,
  353.                PANEL_EVENT_PROC, button_event_proc,
  354.                PANEL_NOTIFY_PROC, view_button_proc,
  355.                0);
  356.  
  357.   horizontal_sweep_button_menu =
  358.     menu_create(MENU_STRINGS, "Horizontal Sweep", 0, 0);
  359.   
  360.   vertical_sweep_button =
  361.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  362.               PANEL_ITEM_X, 51,
  363.               PANEL_ITEM_Y, 1,
  364.               PANEL_LABEL_IMAGE, &vertical_sweep_pr,
  365.               PANEL_EVENT_PROC, button_event_proc,
  366.               PANEL_NOTIFY_PROC, view_button_proc,
  367.               0);
  368.   
  369.   vertical_sweep_button_menu =
  370.     menu_create(MENU_STRINGS, "Vertical Sweep", 0, 0);
  371.   
  372.   tilt_button =
  373.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  374.               PANEL_ITEM_X, 101,
  375.               PANEL_ITEM_Y, 1,
  376.               PANEL_LABEL_IMAGE, &tilt_pr,
  377.               PANEL_EVENT_PROC, button_event_proc,
  378.               PANEL_NOTIFY_PROC, view_button_proc,
  379.               0);
  380.   
  381.   tilt_button_menu =
  382.     menu_create(MENU_STRINGS, "Tilt", 0, 0);
  383.   
  384.   horizontal_pan_button =
  385.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  386.               PANEL_ITEM_X, 1,
  387.               PANEL_ITEM_Y, 50,
  388.               PANEL_LABEL_IMAGE, &horizontal_pan_pr,
  389.               PANEL_EVENT_PROC,  button_event_proc,
  390.               PANEL_NOTIFY_PROC, view_button_proc,
  391.               0);
  392.  
  393.   horizontal_pan_button_menu =
  394.     menu_create(MENU_STRINGS, "Horizontal Pan", 0, 0);
  395.   
  396.   vertical_pan_button =
  397.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  398.               PANEL_ITEM_X, 51,
  399.               PANEL_ITEM_Y, 50,
  400.               PANEL_LABEL_IMAGE, &vertical_pan_pr,
  401.               PANEL_EVENT_PROC, button_event_proc,
  402.               PANEL_NOTIFY_PROC, view_button_proc,
  403.               0);
  404.   
  405.   vertical_pan_button_menu =
  406.     menu_create(MENU_STRINGS, "Vertical Pan", 0, 0);
  407.   
  408.   perspective_button =
  409.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  410.               PANEL_ITEM_X, 101,
  411.               PANEL_ITEM_Y, 50,
  412.               PANEL_LABEL_IMAGE, &perspective_pr,
  413.               PANEL_EVENT_PROC, button_event_proc,
  414.               PANEL_NOTIFY_PROC, view_button_proc,
  415.               0);
  416.   
  417.   perspective_button_menu =
  418.     menu_create(MENU_STRINGS, "Perspective", 0, 0);
  419.   
  420.   zoom_button =
  421.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  422.               PANEL_ITEM_X, 1,
  423.               PANEL_ITEM_Y, 99,
  424.               PANEL_LABEL_IMAGE, &zoom_pr,
  425.               PANEL_EVENT_PROC, button_event_proc,
  426.               PANEL_NOTIFY_PROC, view_button_proc,
  427.               0);
  428.   
  429.   zoom_button_menu =
  430.     menu_create(MENU_STRINGS, "Zoom", 0, 0);
  431.   
  432.   redraw_button =
  433.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  434.               PANEL_ITEM_X, 51,
  435.               PANEL_ITEM_Y, 99,
  436.               PANEL_LABEL_IMAGE, &redraw_pr,
  437.               PANEL_EVENT_PROC, button_event_proc,
  438.               PANEL_NOTIFY_PROC, view_button_proc,
  439.               0);
  440.   
  441.   redraw_button_menu =
  442.     menu_create(MENU_STRINGS, "Redraw", 0,0);
  443.   
  444.   reset_button =
  445.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  446.               PANEL_ITEM_X, 101,
  447.               PANEL_ITEM_Y, 99,
  448.               PANEL_LABEL_IMAGE, &reset_pr,
  449.               PANEL_EVENT_PROC, button_event_proc,
  450.               PANEL_NOTIFY_PROC, view_button_proc,
  451.               0);
  452.   
  453.   reset_button_menu =
  454.     menu_create(MENU_STRINGS, "Reset", 0, 0);
  455.   
  456.   anim_button =
  457.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  458.               PANEL_ITEM_X, 51,
  459.               PANEL_ITEM_Y, 148,
  460.               PANEL_LABEL_IMAGE, &anim_pr,
  461.               PANEL_EVENT_PROC, button_event_proc,
  462.               PANEL_NOTIFY_PROC, anim_button_proc,
  463.               0);
  464.   
  465.   anim_button_menu =
  466.     menu_create(MENU_STRINGS, "Animation", 0, 0);
  467.   
  468.   view_data_button =
  469.     panel_create_item(GR_view_control_panel, PANEL_BUTTON, 
  470.               PANEL_ITEM_X, 1,
  471.               PANEL_ITEM_Y, 148,
  472.               PANEL_LABEL_IMAGE, &view_data_pr,
  473.               PANEL_EVENT_PROC, button_event_proc,
  474.               PANEL_NOTIFY_PROC, view_data_button_proc,
  475.               0);
  476.   
  477.   view_data_button_menu =
  478.     menu_create(MENU_STRINGS, "Viewing Transformation", 0, 0);
  479.   
  480.   rotation_angle_slider =
  481.     panel_create_item(GR_view_control_panel, PANEL_SLIDER, 
  482.               PANEL_ITEM_X, 14,
  483.               PANEL_ITEM_Y, 234,
  484.               PANEL_VALUE, GR_rotation_angle_slider_value,
  485.               PANEL_SLIDER_WIDTH, 120, 
  486.               PANEL_MIN_VALUE, 0, 
  487.               PANEL_MAX_VALUE, 360, 
  488.               PANEL_SHOW_RANGE, FALSE,
  489.               PANEL_SHOW_VALUE, FALSE,
  490.               PANEL_NOTIFY_LEVEL, PANEL_ALL,
  491.               PANEL_NOTIFY_PROC, rotation_angle_slider_proc,
  492.               0);
  493.   
  494.   rotation_angle_label =
  495.     panel_create_item(GR_view_control_panel, PANEL_MESSAGE,
  496.               PANEL_ITEM_X, 22,
  497.               PANEL_ITEM_Y, 216,
  498.               PANEL_LABEL_STRING, "Rotation Angle",
  499.               0);
  500.   
  501.   rotation_angle_value =
  502.     panel_create_item(GR_view_control_panel, PANEL_MESSAGE,
  503.               PANEL_ITEM_X, 55,
  504.               PANEL_ITEM_Y, 254,
  505.               PANEL_LABEL_STRING,
  506.                   rotation_angle_string(GR_rotation_angle_slider_value),
  507.               0);
  508.   
  509.   zoom_factor_slider =
  510.     panel_create_item(GR_view_control_panel, PANEL_SLIDER, 
  511.               PANEL_ITEM_X, 14,
  512.               PANEL_ITEM_Y, 303,
  513.               PANEL_VALUE, GR_zoom_factor_slider_value,
  514.               PANEL_SLIDER_WIDTH, 120, 
  515.               PANEL_MIN_VALUE, 10, 
  516.               PANEL_MAX_VALUE, 20, 
  517.               PANEL_SHOW_RANGE, FALSE,
  518.               PANEL_SHOW_VALUE, FALSE,
  519.               PANEL_NOTIFY_LEVEL, PANEL_ALL,
  520.               PANEL_NOTIFY_PROC, zoom_factor_slider_proc,
  521.               0);
  522.  
  523.   zoom_factor_label =
  524.     panel_create_item(GR_view_control_panel, PANEL_MESSAGE,
  525.               PANEL_ITEM_X, 37,
  526.               PANEL_ITEM_Y, 285,
  527.               PANEL_LABEL_STRING, "Zoom Factor",
  528.               0);
  529.   
  530.   zoom_factor_value =
  531.     panel_create_item(GR_view_control_panel, PANEL_MESSAGE,
  532.               PANEL_ITEM_X, 55,
  533.               PANEL_ITEM_Y, 323,
  534.               PANEL_LABEL_STRING,
  535.                   zoom_factor_string(GR_zoom_factor_slider_value),
  536.               0);
  537.   
  538.   perspective_factor_slider =
  539.     panel_create_item(GR_view_control_panel, PANEL_SLIDER, 
  540.               PANEL_ITEM_X, 14,
  541.               PANEL_ITEM_Y, 377,
  542.               PANEL_VALUE, GR_perspective_factor_slider_value,
  543.               PANEL_SLIDER_WIDTH, 120, 
  544.               PANEL_MIN_VALUE, 10, 
  545.               PANEL_MAX_VALUE, 20, 
  546.               PANEL_SHOW_RANGE, FALSE,
  547.               PANEL_SHOW_VALUE, FALSE,
  548.               PANEL_NOTIFY_LEVEL, PANEL_ALL,
  549.               PANEL_NOTIFY_PROC, perspective_factor_slider_proc,
  550.               0);
  551.   
  552.   perspective_factor_label =
  553.     panel_create_item(GR_view_control_panel, PANEL_MESSAGE,
  554.               PANEL_ITEM_X, 3,
  555.               PANEL_ITEM_Y, 359,
  556.               PANEL_LABEL_STRING, "Perspective Factor",
  557.               0);
  558.   
  559.   perspective_factor_value =
  560.     panel_create_item(GR_view_control_panel, PANEL_MESSAGE,
  561.               PANEL_ITEM_X, 55,
  562.               PANEL_ITEM_Y, 397,
  563.               PANEL_LABEL_STRING,
  564.          perspective_factor_string(GR_perspective_factor_slider_value),
  565.               0);
  566.  
  567.   drawing_mode_cycle =
  568.     panel_create_item(GR_view_control_panel, PANEL_CYCLE, 
  569.               PANEL_ITEM_X, 22,
  570.               PANEL_ITEM_Y, 435,
  571.               PANEL_LAYOUT, PANEL_VERTICAL,
  572.               PANEL_LABEL_STRING, "Drawing Mode:",
  573.               PANEL_CHOICE_STRINGS,
  574.                 "Continuous", /* panel_value = 0 */
  575.                 "Batch",      /* panel_value = 1 */
  576.                 0,
  577.               PANEL_NOTIFY_PROC, drawing_mode_cycle_proc,
  578.               PANEL_VALUE, GR_drawing_mode_value,
  579.               0);
  580.   gr_set_batch_mode(GR_drawing_mode_value==1);
  581.   
  582.   for (i=0; i<4; ++i) {
  583.     view_control_panel_message[i] =
  584.       panel_create_item(GR_view_control_panel, PANEL_MESSAGE, 
  585.             PANEL_ITEM_X, view_control_panel_message_x[i],
  586.             PANEL_ITEM_Y, view_control_panel_message_y[i],
  587.             PANEL_LABEL_STRING, "",
  588.             PANEL_LABEL_FONT, GR_bold_font,
  589.             0);
  590.   }
  591.  
  592.   view_data_frame =
  593.     window_create(GR_base_frame, FRAME,
  594.           WIN_FONT, GR_regular_font,
  595.           WIN_X, 587,
  596.           WIN_Y, 618,
  597.           WIN_WIDTH, 411,
  598.           WIN_HEIGHT, 180,
  599.           FRAME_LABEL, "Viewing Transformation",
  600.           FRAME_SHOW_LABEL, TRUE,
  601.           0);
  602.   if (view_data_frame == NULL) goto BAD_WINDOW_ERROR;
  603.   
  604.   view_data_panel =
  605.     window_create(view_data_frame, PANEL,
  606.           WIN_X, 0,
  607.           WIN_Y, 0,
  608.           WIN_FONT, GR_regular_font,
  609.           0);
  610.   if (view_data_panel == NULL) goto BAD_WINDOW_ERROR;
  611.   
  612.   eye_text =
  613.     panel_create_item(view_data_panel, PANEL_TEXT, 
  614.               PANEL_ITEM_X, 15,
  615.               PANEL_ITEM_Y, 10,
  616.               PANEL_VALUE_DISPLAY_LENGTH, VIEW_DATA_TEXT_LENGTH,
  617.               PANEL_LABEL_STRING, "Eye:",
  618.               0);
  619.  
  620.   focus_text =
  621.     panel_create_item(view_data_panel, PANEL_TEXT, 
  622.               PANEL_ITEM_X, 15,
  623.               PANEL_ITEM_Y, 34,
  624.               PANEL_VALUE_DISPLAY_LENGTH, VIEW_DATA_TEXT_LENGTH,
  625.               PANEL_LABEL_STRING, "Focus:",
  626.               0);
  627.   
  628.   up_text =
  629.     panel_create_item(view_data_panel, PANEL_TEXT, 
  630.               PANEL_ITEM_X, 15,
  631.               PANEL_ITEM_Y, 58,
  632.               PANEL_VALUE_DISPLAY_LENGTH, VIEW_DATA_TEXT_LENGTH,
  633.               PANEL_LABEL_STRING, "Up:",
  634.               0);
  635.   
  636.   vpw_message =
  637.     panel_create_item(view_data_panel, PANEL_MESSAGE, 
  638.               PANEL_ITEM_X, 15,
  639.               PANEL_ITEM_Y, 82,
  640.               PANEL_LABEL_STRING, "View Plane Window:",
  641.               0);
  642.   
  643.   vpw_horizontal_text =
  644.     panel_create_item(view_data_panel, PANEL_TEXT, 
  645.               PANEL_ITEM_X, 30,
  646.               PANEL_ITEM_Y, 106,
  647.               PANEL_VALUE_DISPLAY_LENGTH, VIEW_DATA_TEXT_LENGTH,
  648.               PANEL_LABEL_STRING, "Horizontal:",
  649.               0);
  650.   
  651.   vpw_vertical_text =
  652.     panel_create_item(view_data_panel, PANEL_TEXT, 
  653.               PANEL_ITEM_X, 30,
  654.               PANEL_ITEM_Y, 130,
  655.               PANEL_VALUE_DISPLAY_LENGTH, VIEW_DATA_TEXT_LENGTH,
  656.               PANEL_LABEL_STRING, "Vertical:",
  657.               0);
  658.   
  659.   view_data_done_button =
  660.     panel_create_item(view_data_panel, PANEL_BUTTON, 
  661.               PANEL_ITEM_X, 343,
  662.               PANEL_ITEM_Y, 9,
  663.               PANEL_LABEL_IMAGE,
  664.                   panel_button_image(view_data_panel, "Done", 3, 0),
  665.               PANEL_NOTIFY_PROC, view_data_done_button_proc,
  666.               0);
  667.   
  668.   view_data_redraw_button =
  669.     panel_create_item(view_data_panel, PANEL_BUTTON, 
  670.               PANEL_ITEM_X, 341,
  671.               PANEL_ITEM_Y, 41,
  672.               PANEL_LABEL_IMAGE, &redraw_pr,
  673.               PANEL_EVENT_PROC, button_event_proc,
  674.               PANEL_NOTIFY_PROC, view_button_proc,
  675.               0);
  676.   
  677.   redraw_button_menu =
  678.     menu_create(MENU_STRINGS, "Redraw", 0, 0);
  679.   return(0);
  680.  
  681.   BAD_WINDOW_ERROR:
  682.   GR_error("Can't create any more windows !");
  683.   return(1);
  684.  
  685. }
  686.  
  687. /*-----------------------------------------------------------------------
  688.  * Function:    view_data_button_proc
  689.  * Description:    respond to view_data button
  690.  * Args:    (none)
  691.  * Notes:    Turns on view data frame
  692.  */
  693. static int
  694. view_data_button_proc()
  695. {
  696.   window_set( view_data_frame, WIN_SHOW, TRUE, 0 );
  697. }
  698.  
  699. /*-----------------------------------------------------------------------
  700.  * Function:    view_data_done_button
  701.  * Description:    respond to view data frames 'done' button
  702.  * Args:    (none)
  703.  * Notes:    Closes the view data frame
  704.  */
  705. static int
  706. view_data_done_button_proc()
  707. {
  708.   window_set( view_data_frame, WIN_SHOW, FALSE, 0 );
  709. }
  710.  
  711. /*-----------------------------------------------------------------------
  712.  * Function:    rotation_angle_slider_proc
  713.  * Description:    respond to change in value of rotation angle slider
  714.  * Args  IN:    item: slider's handle
  715.  *        value: new value for slider
  716.  *        event: the event which caused the value change
  717.  * Notes:    This updates the display of the slider value and
  718.  *        stores the new value in the static global variable
  719.  *        GR_rotation_angle_slider_value.
  720.  */
  721. static int
  722. rotation_angle_slider_proc(item, value, event)
  723.      Panel_item item;
  724.      int value;
  725.      Event *event;
  726. {
  727.   panel_set(rotation_angle_value,
  728.         PANEL_LABEL_STRING, 
  729.           rotation_angle_string(GR_rotation_angle_slider_value=value),
  730.         0);
  731. }
  732.  
  733. /*-----------------------------------------------------------------------
  734.  * Function:    zoom_factor_slider_proc
  735.  * Description:    respond to change in value of zoom factor slider
  736.  * Args  IN:    item: slider's handle
  737.  *        value: new value for slider
  738.  *        event: the event which caused the value change
  739.  * Notes:    This updates the display of the slider value and
  740.  *        stores the new value in the static global variable
  741.  *        GR_zoom_factor_slider_value.
  742.  */
  743. static int
  744. zoom_factor_slider_proc(item, value, event)
  745.      Panel_item item;
  746.      int value;
  747.      Event *event;
  748. {
  749.   panel_set(zoom_factor_value,
  750.         PANEL_LABEL_STRING, 
  751.           zoom_factor_string(GR_zoom_factor_slider_value=value),
  752.         0);
  753. }
  754.  
  755. /*-----------------------------------------------------------------------
  756.  * Function:    perspective_factor_slider_proc
  757.  * Description:    respond to change in value of perspective factor slider
  758.  * Args  IN:    item: slider's handle
  759.  *        value: new value for slider
  760.  *        event: the event which caused the value change
  761.  * Notes:    This updates the display of the slider value and
  762.  *        stores the new value in the static global variable
  763.  *        GR_perspective_factor_slider_value.
  764.  */
  765. static int
  766. perspective_factor_slider_proc(item, value, event)
  767.      Panel_item item;
  768.      int value;
  769.      Event *event;
  770. {
  771.   panel_set(perspective_factor_value,
  772.         PANEL_LABEL_STRING, 
  773.           perspective_factor_string(GR_perspective_factor_slider_value=value),
  774.         0);
  775. }
  776.  
  777. /*-----------------------------------------------------------------------
  778.  * Function:    rotation_angle_string
  779.  * Description:    format a string for displaying the rotation angle
  780.  * Args  IN:    value: integer value of rotation angle slider
  781.  * Returns:    pointer to formatting string
  782.  */
  783. static char *
  784. rotation_angle_string(value)
  785.      int value;
  786. {
  787.   static char buf[10];
  788.  
  789.   sprintf(buf, "[%3d]",
  790.     (int)SLIDER_VALUE_TO_ROTATION_ANGLE(GR_rotation_angle_slider_value));
  791.   return(buf);
  792. }
  793.  
  794. /*-----------------------------------------------------------------------
  795.  * Function:    zoom_factor_string
  796.  * Description:    format a string for displaying the zoom factor
  797.  * Args  IN:    value: integer value of zoom factor slider
  798.  * Returns:    pointer to formatting string
  799.  */
  800. static char *
  801. zoom_factor_string(value)
  802.      int value;
  803. {
  804.   static char buf[10];
  805.  
  806.   sprintf(buf, "[%3.1f]",
  807.       SLIDER_VALUE_TO_ZOOM_FACTOR(GR_zoom_factor_slider_value));
  808.   return(buf);
  809. }
  810.  
  811. /*-----------------------------------------------------------------------
  812.  * Function:    perspective_factor_string
  813.  * Description:    format a string for displaying the perspective factor
  814.  * Args  IN:    value: integer value of perspective factor slider
  815.  * Returns:    pointer to formatting string
  816.  */
  817. static char *
  818. perspective_factor_string(value)
  819.      int value;
  820. {
  821.   static char buf[10];
  822.  
  823.   sprintf(buf, "[%3.1f]",
  824.       SLIDER_VALUE_TO_ZOOM_FACTOR(GR_perspective_factor_slider_value));
  825.   return(buf);
  826. }
  827.  
  828. static int
  829. drawing_mode_cycle_proc()
  830. {
  831.   int batching;
  832.  
  833.   batching = ((int)panel_get_value(drawing_mode_cycle) == 1);
  834.   gr_set_batch_mode(batching);
  835. }
  836.  
  837. static int
  838. view_button_proc(item, event)
  839.      Panel_item item;
  840.      Event *event;
  841. {
  842.   int sign, frame;
  843.   char msg[GR_ANIM_MESSAGE_LENGTH+1];
  844.  
  845.   if (GR_recording_trigger) {
  846.     GR_recording_trigger=0;
  847.     GR_interrupted=0;
  848.     GR_anim_message_clear();
  849.     GR_show_error_message("Hit the STOP key (L1) to interrupt the filming");
  850.     for (frame=0;
  851.      ((frame<GR_recording_count) && (!GR_interrupted));
  852.      ++frame) {
  853.       GR_save_frame();
  854.       sprintf(msg,"Saved Frame %2d", frame+1);
  855.       GR_show_anim_message(msg,0);
  856.       if (!GR_interrupted) view_button_proc(item, event);
  857.     }
  858.     GR_anim_message_clear();
  859.     GR_show_error_message("");
  860.     if (GR_interrupted) {
  861.       sprintf(msg,"Recording stoped after %1d frames", frame);
  862.       GR_show_anim_message(msg,1);
  863.     }
  864.     else {
  865.       sprintf(msg,"%1d frames saved", GR_recording_count);
  866.       GR_show_anim_message(msg,0);
  867.     }
  868.     return;
  869.   }
  870.  
  871.   sign = event_shift_is_down(event) ? -1 : 1;
  872.  
  873.   if (item == vertical_sweep_button)
  874.     gr_vertical_sweep(sign * 
  875.           SLIDER_VALUE_TO_ROTATION_ANGLE(GR_rotation_angle_slider_value));
  876.  
  877.   else if (item == horizontal_sweep_button)
  878.     gr_horizontal_sweep(sign *
  879.           SLIDER_VALUE_TO_ROTATION_ANGLE(GR_rotation_angle_slider_value));
  880.  
  881.   else if (item == vertical_pan_button)
  882.     gr_vertical_pan(sign * GR_pan_factor *
  883.           SLIDER_VALUE_TO_ROTATION_ANGLE(GR_rotation_angle_slider_value));
  884.  
  885.   else if (item == horizontal_pan_button)
  886.     gr_horizontal_pan(sign * GR_pan_factor *
  887.           SLIDER_VALUE_TO_ROTATION_ANGLE(GR_rotation_angle_slider_value));
  888.  
  889.   else if (item == tilt_button)
  890.     gr_tilt(sign *
  891.           SLIDER_VALUE_TO_ROTATION_ANGLE(GR_rotation_angle_slider_value));
  892.  
  893.   else if (item == zoom_button)
  894.     gr_zoom(sign == 1
  895.         ? SLIDER_VALUE_TO_ZOOM_FACTOR(GR_zoom_factor_slider_value)
  896.         : 1/SLIDER_VALUE_TO_ZOOM_FACTOR(GR_zoom_factor_slider_value));
  897.  
  898.   else if (item == perspective_button)
  899.     gr_perspective(sign == 1
  900.     ? SLIDER_VALUE_TO_PERSPECTIVE_FACTOR(GR_perspective_factor_slider_value)
  901.     : 1/SLIDER_VALUE_TO_PERSPECTIVE_FACTOR(GR_perspective_factor_slider_value));
  902.  
  903.   else if (item == reset_button)
  904.     gr_reset();
  905.   else if ( (item == redraw_button) || (item == view_data_redraw_button) )
  906.     gr_redraw();
  907.   else
  908.     GR_error("Unknown button event !");
  909. }
  910.  
  911. static int
  912.   anim_button_proc()
  913. {
  914.   GR_show_anim_frame();
  915. }
  916.  
  917. static int
  918.   read_defaults()
  919. {
  920.   char current[80], *cval, buf[10];
  921.   double dval;
  922.   int ival, i;
  923.  
  924.   sprintf(current, "%s",
  925.       (GR_drawing_mode_value == 0) ? "Continuous" : "Batch");
  926.   cval = defaults_get_string("/LGD/DrawingMode", current, 0);
  927.   GR_drawing_mode_value = (strcmp(cval, "Batch") == 0);
  928.   
  929.   sprintf(current, "%1d", GR_rotation_angle_slider_value);
  930.   ival = atoi(defaults_get_string("/LGD/RotationAngle", current, 0));
  931.   if ((ival >= 0) && (ival <= 360))
  932.     GR_rotation_angle_slider_value = ival;
  933.  
  934.   sprintf(current, "%f", ((double)GR_zoom_factor_slider_value)/10.0);
  935.   dval = atof(defaults_get_string("/LGD/ZoomFactor", current, 0));
  936.   if ((dval >= 1.0) && (dval <= 2.0))
  937.     GR_zoom_factor_slider_value = (int)(10*dval+.5);
  938.  
  939.   sprintf(current, "%f", ((double)GR_perspective_factor_slider_value)/10.0);
  940.   dval = atof(defaults_get_string("/LGD/PerspectiveFactor", current, 0));
  941.   if ((dval >= 1.0) && (dval <= 2.0))
  942.     GR_perspective_factor_slider_value = (int)(10*dval+.5);
  943.  
  944.   sprintf(current, "%f", GR_pan_factor);
  945.   GR_pan_factor =
  946.     atof(defaults_get_string("/LGD/PanFactor", current, 0));
  947.  
  948.   current[0] = '\0';
  949.   for (i=0; i<GR_point_list_count; ++i)
  950.     strcat(current,sprintf(buf," %1d %1d",
  951.                GR_point_list[2*i],
  952.                GR_point_list[2*i+1]));
  953.   cval = defaults_get_string("/LGD/PointList", current, 0);
  954.   interpret_point_list_string(cval);
  955. }
  956.  
  957. /*-----------------------------------------------------------------------
  958.  * Function:    interpret_point_list_string
  959.  * Description:    interpret a character string representing a list of
  960.  *          pixels to plot when plotting points, and set the
  961.  *          global variables GR_point_list and GR_point_list_count
  962.  *          accordingly.
  963.  * Args  IN:    s: the string to interpret
  964.  * Returns:    nothing
  965.  */
  966. static int
  967.   interpret_point_list_string(s)
  968. char *s;
  969. {
  970.   char *x, *y, string[80], *seps = " ,";
  971.   int i, list[80], done;
  972.  
  973.   /* Make a private copy of s to work with */
  974.   strcpy(string, s);
  975.  
  976.   GR_point_list_count = 0;
  977.   done = 0;
  978.   x = strtok(string, seps);
  979.   y = strtok(NULL, seps);
  980.   if ((x == NULL) || (y == NULL))
  981.     done = 1;
  982.   else {
  983.     list[2*GR_point_list_count] = atoi(x);
  984.     list[2*GR_point_list_count+1] = atoi(y);
  985.   }
  986.   while (!done) {
  987.     ++GR_point_list_count;
  988.     x = strtok(NULL, seps);
  989.     y = strtok(NULL, seps);
  990.     if ((x == NULL) || (y == NULL))
  991.       done = 1;
  992.     else {
  993.       list[2*GR_point_list_count] = atoi(x);
  994.       list[2*GR_point_list_count+1] = atoi(y);
  995.     }
  996.   }
  997.   GR_point_list = (int*)malloc(2*GR_point_list_count*sizeof(int));
  998.   for (i=0; i<GR_point_list_count; ++i) {
  999.     GR_point_list[2*i] = list[2*i];
  1000.     GR_point_list[2*i+1] = list[2*i+1];
  1001.   }
  1002. }
  1003.  
  1004. #endif /* End of private 3D version procedures */
  1005.